import { observable, action, computed } from 'mobx'
class NumStore {
  @observable n = 3
  @observable list = []
  @computed get age() {  //计算属性
    return this.n >= 18 ? "你好先生或女士" : "你好小朋友"
  }
  @action
  changeData = () => {
    this.n++;
    // console.log(this.n)
  }
  @action//修饰类的方法
  // 直接写异步
  getData = () => {
    fetch("http://jsonplaceholder.typicode.com/posts")
      .then((res) => res.json()).then((res) => {
        console.log(res);
        this.list = res;
      })
  }
}

// 实例化
var store = new NumStore();
export default store;
